<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">
      
    <ui:composition template="/new-template/template-crud.xhtml">
    	
    	<ui:define name="tituloPagina">
    		<h:outputText value="Cadastro de Cliente :: ZPE" />
    	</ui:define>
    	
    	<ui:define name="parametros">
    	   <ui:param name="bean" value="#{clienteBean}" />
    	</ui:define>
    	
    	<ui:define name="tituloFieldSetFiltro">
    	    <h:outputText value="Pesquisa por Cliente" />
    	</ui:define>
    	
    	<ui:define name="camposFiltro">
			<h:panelGrid columns="2" columnClasses="colunaBusca">
	  	    	<h:outputText value="Código:" />
	  	    	<p:inputMask required="false" 
							 label="Código"
							 value="#{bean.entitySearch.id}"
							 size="20"   
                        	 mask="9999999"> 
                </p:inputMask>

	  	    	<h:outputText value="CNPJ:" />
	  	    	<p:inputMask required="false" 
							 label="CNPJ"
							 value="#{bean.entitySearch.cnpj}"
							 size="20"   
                        	 mask="99.999.999/9999-99"> 
                </p:inputMask>
 
	  	    	<h:outputText value="Razão Social:" />
	  	    	<p:inputText size="40" value="#{bean.entitySearch.razaoSocial}"/>
			</h:panelGrid>
    	</ui:define>
    	
    	<ui:define name="tituloPainel">
    	   <ui:param name="tituloPainel" value="Clientes" />
    	</ui:define>
    	
    	<ui:define name="resultFiltro">
				<p:dataTable align="center" 
   							 width="600px" 
   							 id="result"
   							 rows="10"
   						 	 pageLinks="3"
   						     paginatorAlwaysVisible="false"
   						     emptyMessage="Nenhum Grupo Ocupacional foi encontrado."
   						 value="#{bean.resultSearch}" 
       					 var="var" 
       					 paginator="true"
       					 paginatorPosition="bottom"
       					 rowStyleClass="bgLinha1,bgLinha2">
       					
       						<p:column headerText="" style="width:60px; text-align:center;">
       							<div class="colunaAcao">					    			
									<h:commandButton style="border:none;" 
													 id="cmdUpd" 
													 image="#{resource['img:ico_edit.gif']}"
													 actionListener="#{bean.prepareUpdate}">
										<p:ajax update="painelGlobal" />
									</h:commandButton>
								</div>
       						</p:column>
       						
       						<p:column headerText="Código" style="text-align:center;">
       							<h:outputText value="#{var.id}" />
       						</p:column>
       						
       						<p:column headerText="CNPJ" style="text-align:left;" >
       							<h:outputText value="#{var.cnpj}">
       								<f:convertNumber pattern="99.999.999/9999-99"></f:convertNumber>
       							</h:outputText>
       						</p:column>
       						 
       						<p:column headerText="Razão Social" style="text-align:left;" >
       							<h:outputText value="#{var.razaoSocial}" />
       						</p:column>
       						
       						<p:column headerText="Telefone" style="text-align:left;" >
       							<h:outputText value="#{var.telefone}" />
       						</p:column>
       						
       						<p:column style="width:60px; text-align:center;">
       							<f:facet name="header">
       								<h:selectBooleanCheckbox onchange="checkboxAll(this);" />
       							</f:facet>
       							<h:selectBooleanCheckbox styleClass="selectAll" valueChangeListener="#{bean.select}" />
       						</p:column>
       						
				 	</p:dataTable> 
    	
    	</ui:define>
    	
    	<ui:define name="tituloFieldSetInsert">
		  <h:outputLabel value="&nbsp; Cadastro de Cliente &nbsp;" />
		</ui:define>
    	
    	<ui:define name="camposInsert">
    		<p:tabView id="tabView"> 
    			<p:tab id="cliente" title="Cliente">  
		    		<h:panelGrid columns="4" columnClasses="colunaBusca">
					  <h:outputLabel value="Código: *"/>
					  <p:inputText required="true" 
								   label="Código" readonly="true"
								   value="#{bean.entity.id}" 
								   maxlength="50" 
								   size="40">						
					  </p:inputText>
					   
					  <h:outputLabel value="Tipo de Cliente: *"/>
					  <h:selectOneMenu styleClass="ui-inputfield ui-widget ui-state-default ui-corner-all" label="Tipo de Cliente" id="tipoCliente" style="width:269px"
									   value="#{bean.entity.nivelDeAcesso}" >
							<f:selectItem itemLabel="Selecione o Tipo do Cliente" />
							<f:selectItems value="#{bean.niveis}"/>
					  </h:selectOneMenu> 
					   
					  <h:outputLabel value="Razão Social: *"/>
					  <p:inputText required="true" 
								   label="Razão Social"
								   value="#{bean.entity.razaoSocial}" 
								   maxlength="50" 
								   size="40">						
					  </p:inputText>
					  
					  <h:outputLabel value="CNPJ: *"/>
					  <p:inputMask required="true" 
								   label="CNPJ"
								   value="#{bean.entity.cnpj}"
								   size="40"   
                        		   mask="99.999.999/9999-99"> 
                      </p:inputMask>
					  
					  <h:outputLabel value="Nome Fantasia: *"/>
					  <p:inputText required="true" 
								   label="Nome Fantasia"
								   value="#{bean.entity.descricao}" 
								   maxlength="50" 
								   size="40">						
					  </p:inputText>
					  
					  <h:outputLabel value="Insc. Estadual: "/>
					  <p:inputMask required="false" 
								   label="Insc. Estadual"
								   value="#{bean.entity.inscricaoEstadual}" 
								   size="40"   
                        		   mask="9999999999999999999999999999999999999999999?"> 
                      </p:inputMask> 
					  
					  <h:outputLabel value="Bairro: *"/>
					  <p:inputText required="true" 
								   label="Bairro"
								   value="#{bean.entity.bairro}" 
								   maxlength="50" 
								   size="40">						
					  </p:inputText>
					   
					  <h:outputLabel value="Insc. Municipal: "/> 
					  <p:inputMask required="false" 
								   label="Insc. Municipal"
								   value="#{bean.entity.inscricaoMunicipal}" 
								   size="40"   
                        		   mask="9999999999999999999999999999999999999999999?"> 
                      </p:inputMask> 
					  
					  <h:outputLabel value="CEP: *"/>
					  <p:inputMask required="true" 
								   label="CEP" 
								   value="#{bean.entity.cep}" 
								   size="40" 
								   mask="99999-999">
					  </p:inputMask>
					  
					  <h:outputLabel value="UF: *"/>
					  <h:selectOneMenu styleClass="ui-inputfield ui-widget ui-state-default ui-corner-all" label="UF" id="uf" style="width:269px" converter="converterEntity"
									   value="#{bean.uf}" >
							<f:selectItem itemLabel="Selecione um Estado" />
							<f:selectItems value="#{bean.estados}"/>
							<f:ajax event="change" onclick="carregando.show();" oncomplete="carregando.hide();"  render="municipios" execute="uf" /> 
					  </h:selectOneMenu>  
					  
					  <h:outputLabel value="Endereço: *"/>
					  <h:column> 
							  <p:inputText required="true" 
										   label="Endereço"
										   value="#{bean.entity.endereco}" 
										   maxlength="50" 
										   size="40">						
							  </p:inputText>
							  
							  <h:outputLabel value="*"/>
							  <p:inputText required="true" 
										   label="Número"
										   value="#{bean.entity.numero}" 
										   maxlength="50" 
										   size="3">						
							  </p:inputText>
					  </h:column> 
					  
					  <h:outputLabel value="Município: *"/>
					  <h:selectOneMenu styleClass="ui-inputfield ui-widget ui-state-default ui-corner-all" label="UF" style="width:269px" id="municipios"
									   value="#{bean.entity.municipio}" converter="converterEntity">
							<f:selectItem itemLabel="Selecione um Município" />
							<f:selectItems value="#{bean.municipios}"></f:selectItems>					
					  </h:selectOneMenu> 
					   
					  <h:outputLabel value="Complemento: "/>
					  <p:inputText required="false" 
								   label="Complemento:"
								   value="#{bean.entity.complemento}" 
								   maxlength="50" 
								   size="40">						
					  </p:inputText>
					  
					  <h:outputLabel value="Celular (ddd-nº): "/>
					  <p:inputMask required="false" 
								   label="Celular (ddd-nº)"
								   value="#{bean.entity.celular}" 
								   size="40"   
                        		   mask="(99) 9999-99999"> 
                      </p:inputMask> 
					  
					  <h:outputLabel value="Fax (ddd-nº): "/>
					  <p:inputMask required="false" 
								   label="Fax (ddd-nº)"
								   value="#{bean.entity.fax}" 
								   size="40"   
                        		   mask="(99) 9999-9999"> 
                      </p:inputMask>
					   
					  <p:spacer />
					  <p:spacer />
					  
					  <h:outputLabel value="Telefone (ddd-nº): *"/>
					  <p:inputMask required="true" 
								   label="Telefone (ddd-nº)"
								   value="#{bean.entity.telefone}" 
								   size="40"   
                        		   mask="(99) 9999-9999"> 
                      </p:inputMask>
					  
					  <p:spacer /> 
					  <p:spacer /> 
					  
					  <h:outputLabel value="Passaporte: "/>
					  <p:inputText required="false" 
								   label="Passaporte"
								   value="#{bean.entity.passaporte}" 
								   maxlength="50" 
								   size="40">						
					  </p:inputText>
					  
					</h:panelGrid>
					<h:panelGrid columns="2" columnClasses="colunaBusca"> 
						<p:fieldset legend="Cliente Antaq" style="height:190px; width:400px">
							<h:selectOneRadio required="true" 
									   label="Cliente Antaq"
									   value="#{bean.entity.clienteAntaq}"
									   size="40">
									   <f:selectItem itemValue="P" itemLabel="Próprio"></f:selectItem>
									   <f:selectItem itemValue="T" itemLabel="Terceiro"></f:selectItem>
						  	</h:selectOneRadio>
						  	
						  	<h:panelGrid columns="2" columnClasses="colunaBusca">
							  	<h:outputLabel value="Início: *"/> 
							  	<p:calendar readOnlyInputText="true" pattern="dd/MM/yyyy" value="#{bean.entity.dataInicio}" id="dataInicio" showOn="button" /> 
							  	 
							  	<h:outputLabel value="Fim: *"/>
							  	<p:calendar readOnlyInputText="true" pattern="dd/MM/yyyy" value="#{bean.entity.dataFim}" id="dataFim" showOn="button" />
						  	</h:panelGrid>   
						</p:fieldset>
						 
						<p:fieldset id="fieldEmail" legend="E-mails Cadastrados" style="height:190px; width:400px">

							  <h:panelGrid columns="3" columnClasses="colunaBusca" id="panelEmail">
								  <h:outputLabel value="Email: *"/>
								  <p:inputText required="false" 
											   label="Email" id="emailInput"
											   value="#{bean.email.descricao}" 
											   maxlength="50" 
											   size="33">	 					
								  </p:inputText>   
								   
								  <p:commandButton styleClass="btIcon" 
											 value="Adicionar"
											 image="saveIcon" process="@this emailInput"  
											 actionListener="#{bean.adicionaEmail}"   
											 update=":formCadastro:fieldEmail" />	       
							  </h:panelGrid>
							  <h:panelGrid id="resultEmails" columns="1" columnClasses="colunaBusca" style="width:400px">
								  <p:dataTable align="center" 
		   							 width="400px"  
		   							 id="resultEmailsData"  
		   							 rows="2"  
		   						 	 pageLinks="3"
		   						     paginatorAlwaysVisible="false"
		   						     emptyMessage="Nenhum e-mail cadastrado."
			   						 value="#{bean.listEmail}" 
			       					 var="var" 
			       					 paginator="true"
			       					 paginatorPosition="bottom"
			       					 rowStyleClass="bgLinha1,bgLinha2">
				       					 
				       					 <p:column headerText="E-mail" style="text-align:center;width:300px">
		       									<h:outputText value="#{var.descricao}" />
		       							 </p:column>
		       							 
		       							 <p:column headerText="Excluir" style="text-align:center;">
		       									<div class="colunaAcao">					    			
													<h:commandButton style="border:none;" 
																	 id="cmdDel" 
																	 image="#{resource['img:icon_remover.jpg']}"
																	 actionListener="#{bean.removeEmail}">
														<p:ajax update=":formCadastro:fieldEmail" />
													</h:commandButton>
												</div>
		       							 </p:column>
				       					 
				       				</p:dataTable> 
								</h:panelGrid>
						</p:fieldset>
					</h:panelGrid>
					
					<h:panelGrid columns="2" columnClasses="colunaBusca">
						<h:outputLabel value="Ativo: "/>
						<h:selectOneRadio required="true" 
									   label="Ativo"
									   value="#{bean.entity.ativo}"
									   size="40">
									   <f:selectItem itemValue="S" itemLabel="Sim"></f:selectItem>
									   <f:selectItem itemValue="N" itemLabel="Não"></f:selectItem>
						</h:selectOneRadio>
					</h:panelGrid>	
					<h:panelGrid columns="2" columnClasses="colunaBusca">
						<h:selectBooleanCheckbox />
						<h:outputLabel value="Substituto Municipal"/>
						
						<h:selectBooleanCheckbox />
						<h:outputLabel value="Substituto Federal"/>
					</h:panelGrid>
				</p:tab>
				<p:tab id="usuarios" title="Usuários"> 
					<p:fieldset id="fieldUsers" legend="Pesquisa por Usuários" style="width:98%">
						<h:panelGrid id="resultUsuarios" columns="1" columnClasses="colunaBusca" style="width:100%">
							<h:column>
								<h:outputLabel value="Usuário:"></h:outputLabel>
								<p:inputText value="#{bean.pesquisa}" style="width:250px" id="pesquisaUsuario"></p:inputText>
								<p:commandButton styleClass="btIcon" 
												 value="Pesquisar"
												 image="searchIcon" process="@this pesquisaUsuario"  
												 actionListener="#{bean.findCliente}"   
												 update=":formCadastro:fieldUsers :formCadastro:fieldUsersPermission" />
							</h:column>	
							<h:panelGrid id="resultUsuariosDataTableSearch" columns="1" columnClasses="colunaBusca" style="width:100%">
								<p:dataTable align="center" 
			   							 width="350px"   
			   							 id="resultUsariosDataSearch"  
			   							 rows="2"  
			   						 	 pageLinks="3"
			   						     paginatorAlwaysVisible="false"
			   						     emptyMessage="Nenhum usuário encontrado."
				   						 value="#{bean.usuariosPesquisa}" 
				       					 var="var" 
				       					 paginator="true" 
				       					 paginatorPosition="bottom"
				       					 rowStyleClass="bgLinha1,bgLinha2">
					       					 
					       				 <p:column headerText="Usuário" style="text-align:left;width:50%">
			       							<h:outputText value="#{var.descricao}" />
			       						 </p:column>
			       						 
			       						 <p:column headerText="E-mail" style="text-align:center;width:20%">
			       							<h:outputText value="#{var.email}" />
			       						 </p:column>
			       						 
			       						 <p:column headerText="Login" style="text-align:left;width:20%">
			       							<h:outputText value="#{var.login}" />
			       						 </p:column>  
			       							 
			       						 <p:column headerText="Adicionar" style="text-align:center;width:10%">
			       								<div class="colunaAcao">					    			
													<h:commandButton style="border:none;" 
																	 id="cmdAdd" 
																	 image="#{resource['img:icon_ok.gif']}"
																	 actionListener="#{bean.adicionaCliente}">
														<p:ajax update=":formCadastro:fieldUsers :formCadastro:fieldUsersPermission"/>
													</h:commandButton>
												</div>
			       						 </p:column>	 
					       		</p:dataTable> 
							</h:panelGrid>
							</h:panelGrid>
							</p:fieldset>
							<br />
							<p:fieldset id="fieldUsersPermission" legend="Usuários com Permissão para o Cliente" style="width:98%">      
								<h:panelGrid id="resultUsuariosDataTable" columns="1" columnClasses="colunaBusca" style="width:100%"> 
										  <p:dataTable align="center" 
				   							 width="350px"   
				   							 id="resultUsariosData"   
				   							 rows="2"  
				   						 	 pageLinks="3"
				   						     paginatorAlwaysVisible="false"
				   						     emptyMessage="Nenhum usuário adicionado."
					   						 value="#{bean.usuariosAdicionados}" 
					       					 var="var" 
					       					 paginator="true" 
					       					 paginatorPosition="bottom"
					       					 rowStyleClass="bgLinha1,bgLinha2">
						       					 
						       				 <p:column headerText="Usuário" style="text-align:left;width:50%">
				       							<h:outputText value="#{var.usuario.descricao}" />
				       						 </p:column>
				       						 
				       						 <p:column headerText="E-mail" style="text-align:center;width:20%">
				       							<h:outputText value="#{var.usuario.email}" />
				       						 </p:column>
				       						 
				       						 <p:column headerText="Login" style="text-align:left;width:20%">
				       							<h:outputText value="#{var.usuario.login}" />
				       						 </p:column>  
				       							 
				       						 <p:column headerText="Excluir" style="text-align:center;width:10%">
				       								<div class="colunaAcao">					    			
														<h:commandButton style="border:none;" 
																		 id="cmdDel" 
																		 image="#{resource['img:icon_remover.jpg']}"
																		 actionListener="#{bean.removeCliente}">
															<p:ajax update=":formCadastro:fieldUsers :formCadastro:fieldUsersPermission" />
														</h:commandButton>
													</div>
				       						 </p:column>	 
						       		</p:dataTable>
						       	</h:panelGrid>
					       	</p:fieldset> 
						
										
				</p:tab>
			</p:tabView>
    	</ui:define>
    	
    </ui:composition>
</html>